﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace multi_thread
{
    class Cat {
        private int times_;
        public Cat(int times) { times_ = times; }
        public void work() {
            while (times_-->0) {
                System.Console.WriteLine("{0} > miaomiao {1}",DateTime.Now.ToString(),times_);
                System.Threading.Thread.Sleep(1000);
            }
        }
    }

    class Doggy {
        private int times_;
        public Doggy(int times) { times_ = times; }
        public void work()
        {
            while (times_-->0)
            {
                System.Console.WriteLine("{0} > wangwang{1}", DateTime.Now.ToString(), times_);
                System.Threading.Thread.Sleep(1000);
            }
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            Cat cat = new Cat(5);
            Doggy doggy = new Doggy(5);
            // 创建两个前台线程，处理两个常驻任务。
            Thread cat_thread = new Thread(cat.work);
            Thread doggy_thread = new Thread(doggy.work);
            cat_thread.Start();
            doggy_thread.Start();

            cat_thread.Join();
            doggy_thread.Join();
        }
    }
}
